<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>post请求</title>
</head>
<style>
    .box {
        width: 200px;
        height: 200px;
        margin: 0 auto;
        color: red;
        border: 1px red solid;
    }
</style>

<body>

    <div class="box">

    </div>

</body>
<script>
    // 找到div
    var box = document.querySelector('div')
    //  鼠标移入事件
    box.onmouseover = function () {
        //   1.创建对象
        const xhr = new XMLHttpRequest()

        // 2.初始化 请求方法
        xhr.open('POST', 'http://127.0.0.1:8000/serve?a=100&b=200')

        // fasong
        xhr.send()

        // 4. 事件绑定 处理服务器返回结果
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4) {
                if (xhr.status === 200) {
                    box.innerHTML = xhr.response
                }
            }
        }
    }
    //  鼠标移入事件
    box.onmouseout = function () {
        box.innerHTML = ''
    }
</script>

</html>